package com.baby.growth.controller;

import com.baby.growth.module.BabyInput;
import com.baby.growth.service.BabyInputService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class BabyInputController {
    @Autowired
    BabyInputService babyInputService;

    @GetMapping("/api/babyinputdatas")
    public List<BabyInput> list() throws Exception {
        return babyInputService.list();
    }

    @GetMapping("/api/babyinputtodaydatas")
    public List<BabyInput> listToday() throws Exception {
        return babyInputService.listToday();
    }

    @PostMapping("/api/babyinputdata")
    public BabyInput addOrUpdate(@RequestBody BabyInput babyInput) throws Exception {
        babyInputService.addOrUpdate(babyInput);
        return babyInput;
    }

    @PostMapping("/api/babyinputdata/delete")
    public void deleted(@RequestBody BabyInput babyInput) throws Exception {
        babyInputService.deleteById(babyInput.getId());
    }
}
